from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey
from sqlalchemy.orm import relationship
from app.core.database import Base
from datetime import datetime

class News(Base):
    __tablename__ = "news"
    
    id = Column(Integer, primary_key=True, index=True)
    title = Column(String(200), nullable=False, comment="新闻标题")
    content = Column(Text, nullable=False, comment="新闻内容")
    image = Column(String(500), comment="新闻图片URL")
    author_id = Column(Integer, ForeignKey("users.id"), nullable=False, comment="作者ID")
    created_at = Column(DateTime, default=datetime.utcnow, comment="创建时间")
    updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, comment="更新时间")
    
    # 添加与User的关系
    author = relationship("User", back_populates="news")